package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.CarListEntity
import com.c.ctgproject.ui.collect.*
import com.c.ctgproject.utils.*
import org.jetbrains.anko.startActivity

class CarSearchAdapter(private val context: Context, private val mList: List<CarListEntity.DataBean.ListBean>,private val listener:CarSearchCallBack) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_car_search_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {

        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mUserNameTV.text = data.createPersonName.noDataHandler()
            holder.mVinTV.text = data.carVin.noDataHandler()
            holder.mCarCodeTV.text = data.carCode.noDataHandler()
            holder.mCarFromTV.text = data.carSource.noDataHandler()
            holder.carPlate.text = data.carPlate.noDataHandler()

            val carType = when (data.carType) {
                1 -> "社会车"
                2 -> "试验车"
                3 -> "外包车"
                4 -> "五类车"
                5 -> "农机具"
                else -> "暂无数据"
            }
            holder.mCarModelTV.text = carType
            val carStatus = when (data.carStatus) {
                1 -> "整车"
                2 -> "车架"
                else -> "暂无数据"
            }
            holder.mCarStatueTV.text = carStatus
            holder.mTimeTV.text = data.createTime.noDataHandler()

            holder.mParentLL.setOnClickListener {
                //车辆详情
                context.startActivity<SearchCarInfoActivity>(MyConstants.CAR_ID to data.carId)
            }
            //holder.mHandlerBatterRL.visibility=if(data.isRemove==1)View.VISIBLE else View.GONE
            holder.mHandlerBatterRL.visibility=View.GONE
            holder.mHandlerBatterBTN.setOnClickListener {
                listener?.deleteItem(position,data)
            }
            holder.mEnergyTypeTV.text=when(data.energy){
                1->"燃油车"
                2->"电动车"
                3->"油电混合"
                else->"暂无数据"
            }
        }
    }
    interface CarSearchCallBack{
        fun deleteItem(position:Int,data:CarListEntity.DataBean.ListBean)
    }
    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val carPlate: TextView = view.findViewById(R.id.carPlate)
        val mCarCodeTV: TextView = view.findViewById(R.id.mCarCodeTV)
        val mCarFromTV: TextView = view.findViewById(R.id.mCarFromTV)
        val mUserNameTV: TextView = view.findViewById(R.id.mUserNameTV)
        val mVinTV: TextView = view.findViewById(R.id.mVinTV)
        val mCarModelTV: TextView = view.findViewById(R.id.mCarModelTV)
        val mCarStatueTV: TextView = view.findViewById(R.id.mCarStatueTV)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
        val mHandlerBatterRL:RelativeLayout=view.findViewById(R.id.mHandlerBatterRL)
        val mHandlerBatterBTN:Button=view.findViewById(R.id.mHandlerBatterBTN)
        val mEnergyTypeTV:TextView=view.findViewById(R.id.mEnergyTypeTV)
    }
}